/*
 * Copyright 2010 Biz-e (info@biz-e.nl)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.biz_e.gwt.baselib.validation.client.validators;

import java.util.Vector;

/**
 * Validates against a list of forbidden values
 * 
 * @author Joost A. Bloemsma
 */
public class NotEqualsValidator extends BaseValidator {
	private Vector<Object> forbidden = new Vector<Object>();
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean validate(Object value) {
		for (Object forbiddenObj : forbidden) {
			if (forbiddenObj.equals(value))
				return false;
		}
		return true;
	}
	
	/**
	 * Adds a value to the list of forbidden values
	 * 
	 * @param forbiddenObj
	 */
	public void addForbidden(Object forbiddenObj) {
		if (forbidden.contains(forbiddenObj))
			return;
		forbidden.add(forbiddenObj);
	}
	
	/**
	 * Removes a value from the list of forbidden values
	 * 
	 * @param forbiddenObj
	 */
	public void removeForbidden(Object forbiddenObj) {
		forbidden.remove(forbiddenObj);
	}
	
	/**
	 * Sets a forbidden value. If there are allready values set, they will be
	 * erased
	 * 
	 * @param forbiddenObj
	 */
	public void setForbidden(Object forbiddenObj) {
		resetForbidden();
		addForbidden(forbiddenObj);
	}
	
	/**
	 * Clears the list of forbidden values
	 */
	public void resetForbidden() {
		forbidden.clear();
	}
}
